/* ==========================================================
   Brandywine Tree & Shrub — Chatbot Widget
   ========================================================== */

/* ── FAB Trigger Button ── */
.chat-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9000;
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--canopy), var(--forest));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(45, 80, 22, 0.4), 0 2px 8px rgba(0,0,0,0.15);
  transition: transform var(--dur-normal) var(--ease-spring),
              box-shadow var(--dur-normal) var(--ease-out);
  color: var(--white);
}

.chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 30px rgba(45, 80, 22, 0.5), 0 4px 12px rgba(0,0,0,0.2);
}

.chat-fab:active {
  transform: scale(0.96);
}

.chat-fab svg {
  width: 26px;
  height: 26px;
  transition: opacity var(--dur-fast) var(--ease-out),
              transform var(--dur-normal) var(--ease-spring);
  position: absolute;
}

.chat-fab .icon-chat   { opacity: 1;  transform: rotate(0deg) scale(1); }
.chat-fab .icon-close  { opacity: 0;  transform: rotate(-90deg) scale(0.5); }

.chat-fab.open .icon-chat  { opacity: 0;  transform: rotate(90deg) scale(0.5); }
.chat-fab.open .icon-close { opacity: 1;  transform: rotate(0deg) scale(1); }

/* Pulse ring */
.chat-fab::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--canopy);
  opacity: 0;
  animation: chat-pulse 3s ease-out infinite;
}

.chat-fab.open::before { animation: none; }

@keyframes chat-pulse {
  0%   { transform: scale(1);   opacity: 0.5; }
  70%  { transform: scale(1.6); opacity: 0; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* Notification dot */
.chat-fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: var(--ember);
  border: 2px solid white;
  font-size: 10px;
  font-weight: var(--fw-bold);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: transform var(--dur-fast) var(--ease-spring),
              opacity var(--dur-fast) var(--ease-out);
}

.chat-fab.open .chat-fab-badge {
  transform: scale(0);
  opacity: 0;
}

/* ── Chat Window ── */
.chat-window {
  position: fixed;
  bottom: 104px;
  right: 28px;
  z-index: 8999;
  width: 370px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100dvh - 140px);
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 64px rgba(0,0,0,0.15), 0 8px 24px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transform: scale(0.85) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform var(--dur-slow) var(--ease-spring),
              opacity var(--dur-normal) var(--ease-out);
}

.chat-window.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ── Chat Header ── */
.chat-header {
  background: linear-gradient(135deg, var(--forest), var(--canopy));
  padding: var(--sp-lg) var(--sp-xl);
  display: flex;
  align-items: center;
  gap: var(--sp-md);
  flex-shrink: 0;
}

.chat-header-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.chat-header-avatar svg {
  width: 24px;
  height: 24px;
  color: var(--leaf-light);
}

.chat-online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  border-radius: var(--radius-full);
  background: #22c55e;
  border: 2px solid rgba(255,255,255,0.9);
  animation: online-pulse 2.5s ease-in-out infinite;
}

@keyframes online-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

.chat-header-info {
  flex: 1;
  min-width: 0;
}

.chat-header-info strong {
  display: block;
  font-family: var(--ff-heading);
  font-size: 1rem;
  font-weight: var(--fw-semi);
  color: var(--white);
  line-height: var(--lh-tight);
}

.chat-header-info span {
  font-size: var(--fs-xs);
  color: rgba(255,255,255,0.75);
}

.chat-header-actions {
  display: flex;
  gap: var(--sp-xs);
}

.chat-header-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.1);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255,255,255,0.8);
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

.chat-header-btn:hover {
  background: rgba(255,255,255,0.2);
  color: var(--white);
}

.chat-header-btn svg {
  width: 16px;
  height: 16px;
}

/* ── Messages Area ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-lg);
  display: flex;
  flex-direction: column;
  gap: var(--sp-md);
  scroll-behavior: smooth;
  background: hsl(220, 20%, 97%);
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 4px; }

/* ── Message Bubbles ── */
.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-sm);
  max-width: 88%;
  animation: msg-in 0.35s var(--ease-out) both;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-msg.bot { align-self: flex-start; }
.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--canopy), var(--leaf));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--white);
}

.chat-msg-avatar svg { width: 14px; height: 14px; }

.chat-msg-bubble {
  padding: 0.65em 1em;
  border-radius: 18px;
  font-size: 0.9rem;
  line-height: 1.5;
  max-width: 100%;
}

.chat-msg.bot .chat-msg-bubble {
  background: var(--white);
  color: var(--charcoal);
  border-radius: 4px 18px 18px 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.chat-msg.user .chat-msg-bubble {
  background: linear-gradient(135deg, var(--canopy), var(--forest));
  color: var(--white);
  border-radius: 18px 4px 18px 18px;
}

.chat-msg-bubble a {
  color: inherit;
  font-weight: var(--fw-semi);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-msg.bot .chat-msg-bubble a {
  color: var(--forest);
}

/* ── Typing Indicator ── */
.chat-typing {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-sm);
  align-self: flex-start;
  animation: msg-in 0.35s var(--ease-out) both;
}

.chat-typing .chat-msg-avatar {
  width: 28px;
  height: 28px;
}

.typing-dots {
  background: var(--white);
  padding: 0.7em 1em;
  border-radius: 4px 18px 18px 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--gray-400);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-5px); background: var(--canopy); }
}

/* ── Quick Replies ── */
.chat-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-sm);
  padding: var(--sp-sm) var(--sp-lg);
  background: hsl(220, 20%, 97%);
  animation: msg-in 0.4s var(--ease-out) both;
}

.quick-reply-btn {
  padding: 0.45em 0.9em;
  border: 1.5px solid var(--canopy);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--canopy);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  font-family: var(--ff-heading);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  white-space: nowrap;
}

.quick-reply-btn:hover {
  background: var(--canopy);
  color: var(--white);
  transform: translateY(-1px);
}

/* ── Date Separator ── */
.chat-date-sep {
  text-align: center;
  font-size: var(--fs-xs);
  color: var(--gray-400);
  position: relative;
  margin: var(--sp-xs) 0;
}

.chat-date-sep::before,
.chat-date-sep::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--gray-200);
}

.chat-date-sep::before { left: 0; }
.chat-date-sep::after  { right: 0; }

/* ── Input Area ── */
.chat-input-area {
  padding: var(--sp-md) var(--sp-lg);
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 0.65em 1em;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  background: hsl(220, 20%, 97%);
  resize: none;
  outline: none;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.4;
}

.chat-input:focus {
  border-color: var(--canopy);
  box-shadow: 0 0 0 3px rgba(74, 124, 40, 0.1);
  background: var(--white);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--canopy);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  flex-shrink: 0;
  transition: all var(--dur-fast) var(--ease-out);
}

.chat-send-btn:hover  { background: var(--forest); transform: scale(1.08); }
.chat-send-btn:active { transform: scale(0.95); }
.chat-send-btn:disabled { background: var(--gray-200); cursor: not-allowed; transform: none; }

.chat-send-btn svg { width: 18px; height: 18px; }

/* ── Chat Footer Branding ── */
.chat-branding {
  text-align: center;
  padding: 6px;
  font-size: 10px;
  color: var(--gray-400);
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  letter-spacing: 0.02em;
}

/* ── Responsive ── */
@media (max-width: 480px) {
  .chat-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    transform-origin: bottom center;
  }

  .chat-fab {
    bottom: 20px;
    right: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-fab::before { animation: none; }
  .chat-online-dot  { animation: none; }
  .typing-dot       { animation: none; }
  .chat-msg, .chat-quick-replies { animation: none; }
  .chat-window { transition: opacity var(--dur-normal) linear; }
}
